# Maintainer: George Rawlinson <grawlinson@archlinux.org>

pkgname=python-b2sdk
pkgver=1.26.0
pkgrel=1
pkgdesc='Python module to access B2 cloud storage'
arch=('any')
url='https://github.com/Backblaze/b2-sdk-python'
license=('MIT')
depends=(
  'python'
  'python-logfury'
  'python-requests'
  'python-tqdm'
  'python-urllib3'
  'python-setuptools'
  'python-importlib-metadata'
)
makedepends=(
  'git'
  'python-build'
  'python-installer'
  'python-setuptools-scm'
  'python-wheel'
)
checkdepends=(
  'python-pytest'
  'python-pytest-mock'
  'python-pytest-lazy-fixture'
  'python-pyfakefs'
)
_commit='9ca9d0aff203b1f72d0bfd680be35af295eb7da0'
source=(
  "$pkgname::git+$url#commit=$_commit"
  'remove-version-constraint.patch'
)
b2sums=('SKIP'
        '9829d2efe2a93986c21dcce1ddcf74923a2a78c50e8ea1814714aa73eca3adb904664890326f4b3c8ad0a71a0548194bdd586a6afbe69689732b589ee8c72ae9')

pkgver() {
  cd "$pkgname"

  git describe --tags | sed 's/^v//'
}

prepare() {
  cd "$pkgname"

  patch -p1 -i "$srcdir/remove-version-constraint.patch"
}

build() {
  cd "$pkgname"

  SETUPTOOLS_SCM_PRETEND_VERSION="$pkgver" python -m build --wheel --no-isolation
}

check() {
  cd "$pkgname"

  pytest -v \
    --ignore=test/integration \
    --deselect test/static/test_licenses.py::test_files_headers
}

package() {
  cd "$pkgname"

  python -m installer --destdir="$pkgdir" dist/*.whl

  # symlink license file
  local site_packages=$(python -c "import site; print(site.getsitepackages()[0])")
  install -d "$pkgdir/usr/share/licenses/$pkgname"
  ln -s "$site_packages/${pkgname#python-}-$pkgver.dist-info/LICENSE" \
    "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
}
